//
//  XVLable.m
//  整合
//
//  Created by  刘尚威 on 2017/3/3.
//  Copyright © 2017年  刘尚威. All rights reserved.
//

#import "XVLable.h"

@implementation XVLable


//创建label
+ (UILabel *)LabelWithText:(NSString *)text
                      font:(CGFloat)font
                 textColor:(UIColor *)textColor
           backgroundColor:(UIColor *)backgroundColor
             textAlignment:(NSTextAlignment)textAlignment
                 addToView:(UIView *)view
                     frame:(CGRect)frame
{
    UILabel *label = [[UILabel alloc] initWithFrame:frame];
    
    /*字符串不能为空，不然某些特定的判断会出错*/
    //显示的字符串
    if (text == nil) {
        label.text = @"";
    }
    else {
        label.text = text;
    }
    
    //字符串的水平位置
    label.textAlignment = textAlignment;
    
    //字符串大小
    label.font = [UIFont systemFontOfSize:font];
    
    //字符串颜色
    if (textColor == nil) {
        label.textColor = [UIColor blackColor];
    }else{
        label.textColor = textColor;
    }
    
    //背景颜色
    if (backgroundColor == nil) {
        label.backgroundColor = [UIColor clearColor];
    }else{
        label.backgroundColor = backgroundColor;
    }
    
    if (view != nil) {
        [view addSubview:label];
    }
    
    return label;
}



/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
